// JavaScript Document
var home = (function() {
	function init(){
		menuHome();
		scrollingHome();
		createScroll('.search-product-scroll');
		createScroll('.info-cart-scroll');
		chooseSubimages();
		hoverSocial();
        hoverSupport();
	}
	var toggle = 1;
	function menuHome(){
	  
	   $('.nav-menu').hover(function(){
	   		$('.navigation-container').css({'display':'block'});
	   },function(){
	   		$('.navigation-container').css({'display':'none'});
	   });
	  
	}
	
	function hoverSocial(){
		$('.share_social ul li').hover(function(){
	   		$(this).stop().animate({'left':'-70px'});
	   },function(){
	   		$('.share_social ul li').stop().animate({'left':'-5px'});
	   });
	}
    
    function hoverSupport(){
		$('.support').hover(function(){
	   		$(this).stop().animate({'right':'0px'});
            $('.support li span').stop().animate({'opacity':'1'});
	   },function(){
	   		$(this).stop().animate({'right':'-90px'});
            $('.support li span').stop().animate({'opacity':'0'});
	   });
	}
	function chooseSubimages(){
		$('.box-detail .detail-top .big-image ul.sub-images li a').hover(function(){
			var img = $(this).find('img').attr('src');
			$('.box-detail .detail-top .big-image .main-image a.zoomple').attr('href',img.replace('_thumbs/', ''));
			$('.box-detail .detail-top .big-image .main-image a.zoomple').attr('rel',img.replace('_thumbs/', ''));
			$('.box-detail .detail-top .big-image .main-image a.zoomple img').attr('src',img);
		});
	}
    
    ///_/2014/cutkit/www/upload/images/hsth/hs5.jpg
    ///_/2014/cutkit/www/upload/_thumbs/images/hsth/hs5.jpg
	
	function createScroll(clsDiv){
		$(clsDiv).mCustomScrollbar({
			scrollButtons:{
				enable:true
			}
		});
	}
	
	function scrollingHome(){
		var nav = $('.nav-menu');
		var hometop = $('.top-control');
		var container_nav = $('.navigation-container');
		var colorbox = $('.box-color');
        
        var nav_mobile = $('.nav-menu-mobile');
		var top_mobile = $('.top-mobile');
        var box_color_mobile = $('.box-color-mobile');
	    $(window).scroll(function () {
	    	//console.log($(this).scrollTop() ,$('.commonPage .box-right .banner').height() + $('.top-nav').height() );
	        if(is_mobile != '1' && jQuery(window).width() > 768)
            {
                if (($(this).scrollTop() > $('.commonPage .box-right .banner').height() + $('.top-nav').height() + 15)) {
    	            nav.addClass("fixed");
    	            hometop.addClass("fixed");
    	            container_nav.addClass("fixed");
    	            colorbox.addClass("fixed");
                    
    	            //SiteMain.detectFixedMenu();
    	        } else {
    	            nav.removeClass("fixed");
    	            hometop.removeClass("fixed");
    	            container_nav.removeClass("fixed");
    	            colorbox.removeClass("fixed");
    	            //SiteMain.detectFixedMenu();
    	        }                
	        }
            else
            {
                var width_common_page = $('.commonPage').width();
                var nav_menu_mobile = $('.nav-menu-mobile').width();
                if (($(this).scrollTop() > $('.commonPage .box-right .banner').height() + $('.top-nav').height() + 61)) {
    	            
                    if(!nav_mobile.hasClass("fixed"))
                    {
                        nav_mobile.hide();
                        top_mobile.hide();
                        box_color_mobile.hide();
                        
                        nav_mobile.addClass("fixed");
        	            top_mobile.addClass("fixed");
                        box_color_mobile.addClass("fixed");
                        
                        $('.navigation-container').css('width', width_common_page);
                        
                        setTimeout(function(){
                            nav_mobile.fadeIn();
                            top_mobile.fadeIn();
                            box_color_mobile.fadeIn();
                        },300);
                    }
    	        } else {
    	            nav_mobile.removeClass("fixed");
    	            top_mobile.removeClass("fixed");
                    box_color_mobile.removeClass("fixed");
    	        } 
            }
	    });
	}
	
	return {
		init:init
	}
})();	
